/*
 * Copyright 2010-2012 the original author or authors.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package org.jslet.paas.web;

import java.util.HashMap;
import java.util.List;

import javax.annotation.Resource;

import org.eclipse.persistence.dynamic.DynamicEntity;
import org.jslet.paas.modelobject.service.ModelObjectService;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

@Controller
public class BizObjectController
{
	@Resource(name = "modelObjectService")
	private ModelObjectService modelObjectService;

//	@RequestMapping(method = RequestMethod.GET, value = "/metadata", produces = "application/json")
//	public @ResponseBody
//	List<BizModel> getMetaData()
//	{
//		return bizObjectService.getMetaData();
////		return BizModelConfiguration.SINGLETON.getAllBoConfig();
//	}
	@RequestMapping(method = RequestMethod.POST, value = "/bizobject/find/{boName}/{pageNum}/{pageSize}", produces = "application/json", consumes = "application/json")
	public @ResponseBody
	List<DynamicEntity> findAll(@PathVariable String boName, @PathVariable int pageNum, @PathVariable int pageSize, @RequestBody List<HashMap<String, Object>> filters)
	{
		pageNum = 0;
		pageSize = 0;
		List<DynamicEntity> result= this.modelObjectService.findAll(boName, pageNum, pageSize, filters);
		return result;
	}

	@RequestMapping(method = RequestMethod.POST, value = "/bizobject/create/{boName}", produces = "application/json", consumes = "application/json")
	public @ResponseBody
	List<HashMap<String, Object>> createBizObject(@PathVariable String boName,
			@RequestBody List<HashMap<String, Object>> newData)
	{
		this.modelObjectService.createModelObject(boName, newData);
		return newData;
	}

	@RequestMapping(method = RequestMethod.POST, value = "/bizobject/update/{boName}", produces = "application/json", consumes = "application/json")
	public @ResponseBody
	List<HashMap<String, Object>> updateBizObject(@PathVariable final String boName,
			@RequestBody final List<HashMap<String, Object>> modifiedData)
	{
		modelObjectService.updateModelObject(boName, modifiedData);
		return modifiedData;
	}

	@RequestMapping(method = RequestMethod.POST, value = "/bizobject/delete/{boName}", produces = "application/json", consumes = "application/json")
	public @ResponseBody
	List<HashMap<String, Object>> deleteBizObject(@PathVariable String boName,
			@RequestBody List<HashMap<String, Object>> delData)
	{
		this.modelObjectService.deleteModelObject(boName, delData);
		return delData;
	}

}

/*
 * $Log: av-env.bat,v $
 */